Telegram Group & Telegram Channel
127. Program for infix to postfix conversion.

#include<stdio.h>
char ifix[200],pfix[200],stack[100];
int p=0,s=0,i=0;
void fun()
{
if(ifix[i]==')')
{
s--;
while(stack[s]!='(')
pfix[p++]=stack[s--];
}
if(ifix[i]=='+' || ifix[i]=='-')
{
if(!s)
stack[s++]=ifix[i];
else if(stack[s-1]=='(')
stack[s++]=ifix[i];
else
{
s--;
while(s!=-1 && stack[s]!='(')
{
pfix[p++]=stack[s--];
}
stack[++s]=ifix[i];
s++;
}
}
}
int main()
{
printf("Enter your infix expression(using operators +, -, %%, /, *) : ");
scanf("%s",ifix);
for(i;ifix[i]!='\0';i++)
{
if(ifix[i]!='*' && ifix[i]!='/' && ifix[i]!='-' && ifix[i]!='+' && ifix[i]!='(' && ifix[i]!=')' && ifix[i]!='%')
pfix[p++]=ifix[i];
else if(ifix[i]=='(' || ifix[i]=='*' || ifix[i]=='/' || ifix[i]=='%')
stack[s++]=ifix[i];
else
fun();
}
if(ifix[i]=='\0')
{
if(s)
{
s--;
while(s!=-1)
{
if(stack[s]==')' || stack[s]=='(')
s--;
pfix[p++]=stack[s--];
}
}
pfix[p]='\0';
}
printf("The postfix expression is : %s",pfix);
return 0;
}
//used by taking into considering operators +, -, /, *, %, (, )
#program_by : @sidg28



tg-me.com/C_Codings/183
Create:
Last Update:

127. Program for infix to postfix conversion.

#include<stdio.h>
char ifix[200],pfix[200],stack[100];
int p=0,s=0,i=0;
void fun()
{
if(ifix[i]==')')
{
s--;
while(stack[s]!='(')
pfix[p++]=stack[s--];
}
if(ifix[i]=='+' || ifix[i]=='-')
{
if(!s)
stack[s++]=ifix[i];
else if(stack[s-1]=='(')
stack[s++]=ifix[i];
else
{
s--;
while(s!=-1 && stack[s]!='(')
{
pfix[p++]=stack[s--];
}
stack[++s]=ifix[i];
s++;
}
}
}
int main()
{
printf("Enter your infix expression(using operators +, -, %%, /, *) : ");
scanf("%s",ifix);
for(i;ifix[i]!='\0';i++)
{
if(ifix[i]!='*' && ifix[i]!='/' && ifix[i]!='-' && ifix[i]!='+' && ifix[i]!='(' && ifix[i]!=')' && ifix[i]!='%')
pfix[p++]=ifix[i];
else if(ifix[i]=='(' || ifix[i]=='*' || ifix[i]=='/' || ifix[i]=='%')
stack[s++]=ifix[i];
else
fun();
}
if(ifix[i]=='\0')
{
if(s)
{
s--;
while(s!=-1)
{
if(stack[s]==')' || stack[s]=='(')
s--;
pfix[p++]=stack[s--];
}
}
pfix[p]='\0';
}
printf("The postfix expression is : %s",pfix);
return 0;
}
//used by taking into considering operators +, -, /, *, %, (, )
#program_by : @sidg28

BY C Language πŸ‘¨β€πŸ’»


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/C_Codings/183

View MORE
Open in Telegram


C Language ‍ Telegram | DID YOU KNOW?

Date: |

The lead from Wall Street offers little clarity as the major averages opened lower on Friday and then bounced back and forth across the unchanged line, finally finishing mixed and little changed.The Dow added 33.18 points or 0.10 percent to finish at 34,798.00, while the NASDAQ eased 4.54 points or 0.03 percent to close at 15,047.70 and the S&P 500 rose 6.50 points or 0.15 percent to end at 4,455.48. For the week, the Dow rose 0.6 percent, the NASDAQ added 0.1 percent and the S&P gained 0.5 percent.The lackluster performance on Wall Street came on uncertainty about the outlook for the markets following recent volatility.

The Singapore stock market has alternated between positive and negative finishes through the last five trading days since the end of the two-day winning streak in which it had added more than a dozen points or 0.4 percent. The Straits Times Index now sits just above the 3,060-point plateau and it's likely to see a narrow trading range on Monday.

C Language ‍ from us


Telegram C Language πŸ‘¨β€πŸ’»
FROM USA